from dvadmin.utils.models import CoreModel
from django.db import models


# 文件上传
class FileModel(models.Model):
    name = models.CharField(max_length=50)
    file = models.FileField(upload_to='upload')
    # file = models.ImageField()

    class Meta:
        verbose_name = '文件上传'
        verbose_name_plural = verbose_name


class DisposalSubjectModel(CoreModel):
    """处置主体"""
    disposal_subject_id = models.CharField(verbose_name="处置主体id", max_length=32, unique=True)
    disposal_subject_name = models.CharField(verbose_name="处置主体名称", max_length=64)
    disposal_subject_code = models.CharField(verbose_name="处置主体代码", max_length=64)
    watermark_data = models.CharField(verbose_name="盖章水印参数", max_length=1024, null=True)

    class Meta:
        db_table = "disposalsubject"
        verbose_name = '处置主体'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)

        # depart = models.ForeignKey(to="Department", to_field="id", null=True, blank=True, on_delete=models.SET_NULL)


class CaseInfoModel(CoreModel):
    """导入案件信息"""

    # 新增表头
    depart = models.ForeignKey("DisposalSubjectModel",null=True, blank=True, on_delete=models.SET_NULL, verbose_name='处置主体')
    # channel_name = models.CharField(verbose_name='处置主体', max_length=32, null=True, blank=True)
    commission_company = models.ForeignKey('PrincipalModel', null=True, blank=True, on_delete=models.SET_NULL, verbose_name='委外公司')
    # commission_company = models.CharField(verbose_name='委案公司', max_length=32, null=True, blank=True)
    grouping = models.CharField(verbose_name='保全分组', max_length=32, null=True, blank=True)
    product_name = models.CharField(verbose_name='产品名称', max_length=32, null=True, blank=True)
    data_time = models.CharField(verbose_name='取数日期', max_length=32, null=True, blank=True)
    application_time = models.CharField(verbose_name='申请表申请日期', max_length=32, null=True, blank=True)
    acceptance_court = models.CharField(verbose_name='申请法院', max_length=32, null=True, blank=True)
    current_stage = models.CharField(verbose_name='当前阶段', max_length=32, null=True, blank=True)
    current_of = models.CharField(verbose_name='当前状态', max_length=32, null=True, blank=True)
    preservation_amount = models.CharField(verbose_name='保全金额', max_length=32, null=True, blank=True)
    preservation_time = models.CharField(verbose_name='保全立案日期', max_length=32, null=True, blank=True)
    preservation_case = models.CharField(verbose_name='保全案号', max_length=32, null=True, blank=True)
    handle_case  = models.CharField(verbose_name='执保案号', max_length=32, null=True, blank=True)
    relieve_case  = models.CharField(verbose_name='解除保全案号', max_length=64, null=True, blank=True)
    relieve_case_time  = models.CharField(verbose_name='解除保全日', max_length=32, null=True, blank=True)
    mediation_organization_name  = models.CharField(verbose_name='调解组织名称', max_length=32, null=True, blank=True)
    mediators_name  = models.CharField(verbose_name='调解人员姓名', max_length=32, null=True, blank=True)
    mediators_phone  = models.CharField(verbose_name='调解人员电话', max_length=32, null=True, blank=True)
    mediators_wx  = models.CharField(verbose_name='调解人员微信', max_length=32, null=True, blank=True)

    # # 需要对委案批次进行处理
    commission_batch = models.CharField(verbose_name='委案批次', max_length=32, null=True, blank=True)

    # updata_name = models.CharField(verbose_name='上传账号', max_length=32, null=True, blank=True)
    # updata_time = models.CharField(verbose_name='上传时间', max_length=13, null=True, blank=True)
    hand_parting = models.CharField(verbose_name='手别', max_length=12, null=True, blank=True)
    # commission_batch = models.CharField(verbose_name='委托批次', max_length=36)
    commission_area = models.CharField(verbose_name='委外大区', max_length=36, null=True, blank=True)

    blk = models.CharField(verbose_name='BLK', max_length=12, null=True, blank=True)
    commission_start_time = models.CharField(verbose_name='委外起始日期', max_length=12, null=True, blank=True)
    commission_end_time = models.CharField(verbose_name='委外计划截止日期', max_length=12, null=True, blank=True)
    remark = models.CharField(verbose_name='客户号', max_length=16, null=True, blank=True)
    case_no = models.CharField(verbose_name='真账号', max_length=16, null=True, blank=True)
    contract_no = models.CharField(verbose_name='首张激活卡号', max_length=64, null=True, blank=True)
    # principal_amount = models.DecimalField(verbose_name='账户余额本金', max_length=10, max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    principal_amount = models.CharField(verbose_name='账户余额本金', max_length=10, default=0, null=True, blank=True)
    # total_amount = models.DecimalField(verbose_name='人民币余额', max_length=10, max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    total_amount = models.CharField(verbose_name='人民币余额', max_length=10, default=0, null=True, blank=True)
    total_amount_min = models.CharField(verbose_name='人民币最低应缴款金额', max_length=10, default=0, null=True, blank=True)
    # total_amount_min = models.DecimalField(verbose_name='人民币最低应缴款金额', max_length=10, max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    total_amount_min_dollar = models.CharField(verbose_name='美元最低应缴款金额', max_length=10, default=0, null=True, blank=True)
    # total_amount_min_dollar = models.DecimalField(verbose_name='美元最低应缴款金额', max_length=10, max_digits=10, decimal_places=2, default=0, null=True, blank=True)
    entry_reminder_date = models.CharField(verbose_name="入催日", max_length=12, null=True, blank=True)
    account_opening_date = models.CharField(verbose_name="开户日", max_length=12, null=True, blank=True)
    card_suspension_day = models.CharField(verbose_name="停卡日", max_length=12, null=True, blank=True)

    name = models.CharField(verbose_name='客户名称', max_length=16, null=True, blank=True)

    # gender_choices = (
    #     (1, "男"),
    #     (0, "女"),
    # )
    # gender = models.SmallIntegerField(verbose_name='客户性别', max_length=2)
    gender = models.CharField(verbose_name='客户性别', max_length=5, null=True, blank=True)
    id_no = models.CharField(verbose_name='证件号码', max_length=128, null=True, blank=True)
    phone = models.CharField(verbose_name='客户手机号码', max_length=32, null=True, blank=True)
    # home_phone = models.CharField(verbose_name='客户家庭电话', max_length=32, default='')
    # home_adderss = models.CharField(verbose_name='客户家庭地址', max_length=16, default='')
    # email = models.CharField(verbose_name='电邮', max_length=128)
    cal_overdue_days = models.IntegerField(verbose_name='逾期天数', null=True, blank=True)
    date_of_birth = models.CharField(verbose_name='出生日期', max_length=32, null=True, blank=True)
    residence_add = models.CharField(verbose_name='户籍地址', max_length=128, null=True, blank=True)
    disposal_subject = models.CharField(verbose_name='处置主体', max_length=36, null=True, blank=True)
    nation = models.CharField(verbose_name='民族', max_length=12, default="汉")
    application = models.CharField(verbose_name='申请单日', max_length=12, null=True, blank=True)

    amount_owed = models.CharField(verbose_name='欠款总额', max_length=10, default=0, null=True, blank=True)
    principal = models.CharField(verbose_name='本金', max_length=10, default=0, null=True, blank=True)
    interest = models.CharField(verbose_name='利息', max_length=10, default=0, null=True, blank=True)
    default_money = models.CharField(verbose_name='违约金', max_length=10,default=0, null=True, blank=True)
    annual_fee = models.CharField(verbose_name='年费', max_length=10, default=0, null=True, blank=True)
    installment_handling_fee = models.CharField(verbose_name='分期手续费', max_length=10, default=0, null=True, blank=True)
    other_expenses = models.CharField(verbose_name='其他费用', max_length=10, default=0, null=True, blank=True)

    class Meta:
        db_table = "caseinfo"
        verbose_name = '展现列表'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)
        # filter = '__all__'
        # read_only_fields = ["id"]


class PrincipalModel(CoreModel):
    """委外公司相关信息"""
    uuid = models.CharField(verbose_name='委外公司id', max_length=128)
    companyname = models.CharField(verbose_name='委外公司名称', max_length=32, unique=True)
    companycode = models.CharField(verbose_name='委外公司代码', max_length=32, unique=True)

    class Meta:
        db_table = "Principal"
        verbose_name = '委外公司'
        verbose_name_plural = verbose_name


class BatchModel(CoreModel):
    """委案批次信息"""
    uuid = models.CharField(verbose_name='批次ID', max_length=128)
    casebatch = models.CharField(verbose_name="批次", max_length=64)
    company_id = models.ForeignKey('PrincipalModel', null=True, on_delete=models.SET_NULL, verbose_name='委案公司信息')
    mediation_id = models.ForeignKey("MediationModel",null=True, blank=True, on_delete=models.SET_NULL, verbose_name='调解组织信息')

    class Meta:
        db_table = "batch"
        verbose_name = '委案批次'
        verbose_name_plural = verbose_name


class MediationModel(CoreModel):
    """调解组织"""
    uuid = models.CharField(verbose_name="调解组织ID", max_length=16)
    mediatecode = models.CharField(verbose_name="调解组织代码", max_length=16, unique=True)
    mediatename = models.CharField(verbose_name="调解组织名称", max_length=64, unique=True)
    remark = models.CharField(verbose_name="调解组织描述", max_length=1024, null=True)

    class Meta:
        db_table = "mediation"
        verbose_name = '调解组织'
        verbose_name_plural = verbose_name


class PartModel(CoreModel):
    """平台信息"""
    uuid = models.CharField(verbose_name='平台ID', max_length=32)
    platformcode = models.CharField(verbose_name="调解组织代码", max_length=16)
    platformname = models.CharField(verbose_name="调解组织名称", max_length=64)

    class Meta:
        db_table = "part"
        verbose_name = '平台信息'
        verbose_name_plural = verbose_name


class CourtsModel(CoreModel):
    """测试法院信息"""
    uuid = models.CharField(verbose_name='法院id', max_length=32, null=True)
    courtcode = models.CharField(verbose_name="法院代码", max_length=32)
    courtname = models.CharField(verbose_name="法院名称", max_length=64)
    province = models.CharField(verbose_name="省", max_length=10, null=True, blank=True)
    provinceShort = models.CharField(verbose_name="省简写", max_length=10, null=True, blank=True)
    chiefJudge = models.CharField(verbose_name="审判长", max_length=10, null=True, blank=True)
    judge = models.CharField(verbose_name="审判员", max_length=10, null=True, blank=True)
    judge1 = models.CharField(verbose_name="审判员1", max_length=10, null=True, blank=True)
    assistantJudge = models.CharField(verbose_name="法官助理", max_length=10, null=True, blank=True)
    clerk = models.CharField(verbose_name="书记员", max_length=10, null=True, blank=True)
    state = models.CharField(verbose_name="状态", max_length=3, null=True, blank=True)

    class Meta:
        db_table = "courts"
        verbose_name = '平台信息'
        verbose_name_plural = verbose_name


class PlainCompanyModel(models.Model):
    """原告公司"""
    uuid = models.CharField(verbose_name='原告公司id', max_length=32, null=True)
    businessLicense = models.CharField(verbose_name="统一社会信用代码", max_length=64, null=True, blank=True)
    companyName = models.CharField(verbose_name="公司名称", max_length=64, null=True, blank=True)
    companyAddress = models.CharField(verbose_name="公司地址", max_length=128, null=True, blank=True)
    phone = models.CharField(verbose_name="联系电话", max_length=32, null=True, blank=True)
    contacts = models.CharField(verbose_name="联系人话", max_length=32, null=True, blank=True)
    legalRepresentative = models.CharField(verbose_name="法人姓名", max_length=12, null=True, blank=True)
    legalRepresentativeIdNo = models.CharField(verbose_name="法院身份证", max_length=10, null=True, blank=True)
    state = models.CharField(verbose_name="状态", max_length=3, null=True, blank=True)

    class Meta:
        db_table = "plaincompany"
        verbose_name = '原告公司'
        verbose_name_plural = verbose_name